using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TimingScript : MonoBehaviour
{
    public DiceManagingScript DiceManaging;
    public ResultOutputtingScript ResultOutputting;
    public DiceSettings Settings;

    void Start()
    {
        DiceManaging.TossAll();
        tossingTime = Time.time;
        recorded = true; // skip the first toss
    }

    private float tossingTime;
    private bool recorded;
    void Update()
    {
        var now = Time.time;
        var timeDelta = now - tossingTime;
        if (timeDelta > Settings.RecordingTime)
        {
            if(!recorded)
            {
                var (side, headOrTail, bad) = DiceManaging.GetFaceToGround();
                ResultOutputting.Record(side, headOrTail, bad);
                Debug.Log($"side: {side}    head & tail: {headOrTail}    bad: {bad}");
                recorded = true;
            }
            if (timeDelta > Settings.LastingTime)
            {
                DiceManaging.TossAll();
                recorded = false;
                tossingTime = now;
            }
        }
    }
}
